﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using Ext.Net;
using System.Runtime.InteropServices;

using BO = Viewer.BusinessObject.BusinessEntities;
namespace Viewer.NguoiDung.UserControls
{
    public partial class AddNew : System.Web.UI.UserControl
    {
        BO.QUNguoiDung item = new Viewer.BusinessObject.BusinessEntities.QUNguoiDung();
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public void ShowAddNewDialog()
        {
            //AddNew
            this.__DialogType.Text = "AddNew";
            ResetControl();
            wdAddNewHuman.Show();
        }

        public void ShowEditDialog(int pHrId,string type)
        {
            //Edit
            this.__DialogType.Text = "Edit";
            LoadData(pHrId);
            wdAddNewHuman.Show();            
        }

        private void LoadData(int ID)
        {
            BO.QUNguoiDung query = item.LoadDataById(ID);
            txtId.Text = query.NguoiDungID.ToString();
            txtFullName.Text = query.TenDangNhap;
            txtPass.Text = query.MatKhau;
        }

        private void ResetControl()
        {
            txtPass.Text = string.Empty;
            txtFullName.Text = string.Empty;
            txtFullName.Text = string.Empty;
        }

        protected void btnSave_Click(object sender, DirectEventArgs e)
        {
            try
            {

                item.InsertNguoiDung(txtFullName.Text, txtPass.Text);
                ((NguoiDung)this.Page).LoadData();
                wdAddNewHuman.Hide();
            }
            catch 
            {
                throw;
            }
        }

    }
}